package com.yykj.message.center.server.controller;

import com.tencentcloudapi.sms.v20210111.models.SendStatus;
import com.yykj.common.vo.ResultVO;
import com.yykj.message.center.client.dto.MessageDTO;
import com.yykj.message.center.server.service.MessageService;
import com.yykj.message.center.server.util.SmsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author chenl
 * @version 1.0
 * @date 2021/10/25 12:30
 */
@RestController
@Api(tags = "短信发送")
@RequestMapping("/api/message")
@SuppressWarnings("unchecked")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("获取短信验证码")
    @GetMapping("/getCode")
    public ResultVO<MessageDTO> getCode(@RequestParam(name = "phoneNum") String phoneNum) {
        MessageDTO messageDTO = messageService.getCode(phoneNum);
        return ResultVO.success(messageDTO);
    }

    @ApiIgnore
    @ApiOperation("给医生:患者支付成功")
    @GetMapping("/sms/doctor/paySuccess")
    public SendStatus[] smsDoctorPaySuccess(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "consultationType") String consultationType, @RequestParam(name = "dateStr") String dateStr) {
        return SmsUtil.smsSendCommon(SmsUtil.doctorPaySuccessTemplateId, phoneNum, consultationType, dateStr);
    }

    @ApiIgnore
    @ApiOperation("给患者:患者支付成功")
    @GetMapping("/sms/patient/paySuccess")
    public SendStatus[] smsPatientPaySuccess(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName, @RequestParam(name = "consultationType") String consultationType) {
        return SmsUtil.smsSendCommon(SmsUtil.patientPaySuccessTemplateId, phoneNum, doctorName, consultationType);
    }

    @ApiIgnore
    @ApiOperation("给患者:医生已接诊")
    @GetMapping("/sms/patient/doctorReceive")
    public SendStatus[] smsPatientDoctorReceive(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName) {
        return SmsUtil.smsSendCommon(SmsUtil.patientDoctorReceiveTemplateId, phoneNum, doctorName);
    }

    @ApiIgnore
    @ApiOperation("给患者:问诊结束")
    @GetMapping("/sms/patient/consultationFinish")
    public SendStatus[] smsPatientConsultationFinish(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName) {
        return SmsUtil.smsSendCommon(SmsUtil.patientConsultationFinishTemplateId, phoneNum, doctorName);
    }

    @ApiIgnore
    @ApiOperation("给患者:问诊退款")
    @GetMapping("/sms/patient/consultationRefund")
    public SendStatus[] smsPatientConsultationRefund(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName) {
        return SmsUtil.smsSendCommon(SmsUtil.patientConsultationRefundTemplateId, phoneNum, doctorName);
    }

    @ApiIgnore
    @ApiOperation("给患者:电子处方开具成功")
    @GetMapping("/sms/patient/prescriptionSuccess")
    public SendStatus[] smsPatientPrescriptionSuccess(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName) {
        return SmsUtil.smsSendCommon(SmsUtil.patientPrescriptionSuccessTemplateId, phoneNum, doctorName);
    }

    @ApiIgnore
    @ApiOperation("给患者:电子处方到期即将到期前（1天）")
    @GetMapping("/sms/patient/prescriptionTimeout")
    public SendStatus[] smsPatientPrescriptionTimeout(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName) {
        return SmsUtil.smsSendCommon(SmsUtil.patientPrescriptionTimeoutTemplateId, phoneNum, doctorName);
    }

    @ApiIgnore
    @ApiOperation("给患者:信息授权")
    @GetMapping("/sms/patient/grant")
    public SendStatus[] smsPatientgGrant(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName) {
        return SmsUtil.smsSendCommon(SmsUtil.patientgGrantTemplateId, phoneNum, doctorName);
    }

    @ApiIgnore
    @ApiOperation("给患者:预约挂号成功")
    @GetMapping("/sms/patient/appointment")
    public SendStatus[] smsPatientAppointment(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName, @RequestParam(name = "dateStr") String dateStr, @RequestParam(name = "appointmentType") String appointmentType) {
        return SmsUtil.smsSendCommon(SmsUtil.patientAppointmentTemplateId, phoneNum, doctorName, dateStr, appointmentType);
    }

    @ApiIgnore
    @ApiOperation("给患者:预约挂号取消")
    @GetMapping("/sms/patient/appointmentCancel")
    public SendStatus[] smsPatientAppointmentCancel(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName, @RequestParam(name = "dateStr") String dateStr, @RequestParam(name = "appointmentType") String appointmentType) {
        return SmsUtil.smsSendCommon(SmsUtil.patientAppointmentCancelTemplateId, phoneNum, dateStr, doctorName, appointmentType);
    }

    @ApiIgnore
    @ApiOperation("给患者:检查检验")
    @GetMapping("/sms/patient/examine")
    public SendStatus[] smsPatientExamine(@RequestParam(name = "phoneNum") String phoneNum, @RequestParam(name = "doctorName") String doctorName, @RequestParam(name = "examineType") String examineType, @RequestParam(name = "examineType2") String examineType2) {
        return SmsUtil.smsSendCommon(SmsUtil.patientExamineTemplateId, phoneNum, doctorName, examineType, examineType2);
    }

}
